﻿-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Members'
CREATE TABLE [dbo].[Members] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Username] varchar(50)  NOT NULL,
    [PersonalId] varchar(13)  NOT NULL,
    [FirstName] nvarchar(50)  NOT NULL,
    [LastName] nvarchar(50)  NOT NULL,
    [Address] nvarchar(max)  NULL,
    [TelephoneNumber] nvarchar(50)  NULL,
    [PrivilegeLevelId] int  NOT NULL,
    [CreateOn] datetime  NOT NULL,
    [DeleteOn] datetime  NULL
);
GO
-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [PrivilegeLevelId] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [FK_PrivilegeLevelAccount]
    FOREIGN KEY ([PrivilegeLevelId])
    REFERENCES [dbo].[PrivilegeLevels]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [PK_Members]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_PrivilegeLevelAccount'
CREATE INDEX [IX_FK_PrivilegeLevelAccount]
ON [dbo].[Members]
    ([PrivilegeLevelId]);